package o;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteStatement;
import java.util.ArrayList;
import java.util.List;

public class cfu {
    private SQLiteOpenHelper ˋ;
    private String ˎ;

    public cfu(SQLiteOpenHelper sQLiteOpenHelper, String str) {
        this.ˋ = sQLiteOpenHelper;
        this.ˎ = str;
    }

    public long ˎ(cfr o_cfr) {
        long j = -1;
        try {
            j = this.ˋ.getWritableDatabase().insertOrThrow(this.ˎ, null, o_cfr.J_());
        } catch (SQLiteException e) {
            Logger.e("DBHandler", "insert ex : SQLiteException");
        } catch (IllegalStateException e2) {
            Logger.e("DBHandler", "insert ex : " + e2.toString());
        }
        return j;
    }

    public <T extends cfr> void ˎ(List<T> list) {
        SQLiteDatabase writableDatabase;
        Throwable th;
        Throwable th2;
        IllegalStateException e;
        if (list.size() > 0) {
            SQLiteDatabase sQLiteDatabase = null;
            try {
                writableDatabase = this.ˋ.getWritableDatabase();
                try {
                    SQLiteStatement compileStatement = writableDatabase.compileStatement(((cfr) list.get(0)).ʻ(this.ˎ));
                    writableDatabase.beginTransaction();
                    for (T ˋ : list) {
                        ˋ.ˋ(compileStatement);
                        compileStatement.executeInsert();
                    }
                    writableDatabase.setTransactionSuccessful();
                    if (writableDatabase != null) {
                        try {
                            writableDatabase.endTransaction();
                        } catch (Exception e2) {
                            Logger.e("DBHandler", "endTransaction insertBatch ex : " + e2.toString());
                        }
                    }
                } catch (SQLiteException e3) {
                    sQLiteDatabase = writableDatabase;
                    try {
                        Logger.e("DBHandler", "insertBatch ex :SQLiteException");
                        if (sQLiteDatabase != null) {
                            try {
                                sQLiteDatabase.endTransaction();
                            } catch (Exception e22) {
                                Logger.e("DBHandler", "endTransaction insertBatch ex : " + e22.toString());
                            }
                        }
                    } catch (Throwable th3) {
                        th = th3;
                        writableDatabase = sQLiteDatabase;
                        th2 = th;
                        if (writableDatabase != null) {
                            try {
                                writableDatabase.endTransaction();
                            } catch (Exception e4) {
                                Logger.e("DBHandler", "endTransaction insertBatch ex : " + e4.toString());
                            }
                        }
                        throw th2;
                    }
                } catch (IllegalStateException e5) {
                    e = e5;
                    try {
                        Logger.e("DBHandler", "insertBatch ex : " + e.toString());
                        if (writableDatabase != null) {
                            try {
                                writableDatabase.endTransaction();
                            } catch (Exception e222) {
                                Logger.e("DBHandler", "endTransaction insertBatch ex : " + e222.toString());
                            }
                        }
                    } catch (Throwable th4) {
                        th2 = th4;
                        if (writableDatabase != null) {
                            writableDatabase.endTransaction();
                        }
                        throw th2;
                    }
                }
            } catch (SQLiteException e6) {
                Logger.e("DBHandler", "insertBatch ex :SQLiteException");
                if (sQLiteDatabase != null) {
                    sQLiteDatabase.endTransaction();
                }
            } catch (IllegalStateException e7) {
                IllegalStateException illegalStateException = e7;
                writableDatabase = null;
                e = illegalStateException;
                Logger.e("DBHandler", "insertBatch ex : " + e.toString());
                if (writableDatabase != null) {
                    writableDatabase.endTransaction();
                }
            } catch (Throwable th32) {
                th = th32;
                writableDatabase = null;
                th2 = th;
                if (writableDatabase != null) {
                    writableDatabase.endTransaction();
                }
                throw th2;
            }
        }
    }

    private Cursor ˊ(String str, String[] strArr, String str2) {
        try {
            return this.ˋ.getWritableDatabase().query(this.ˎ, new String[]{"*"}, str, strArr, null, null, str2);
        } catch (SQLiteException e) {
            Logger.e("DBHandler", "query ex :SQLiteException");
            return null;
        } catch (Throwable e2) {
            Logger.ˋ("DBHandler", "query ex:", e2);
            return null;
        }
    }

    public <T extends cfr> List<T> ˋ(Class<T> cls, String str) {
        List<T> arrayList = new ArrayList();
        Cursor ˊ = ˊ(null, null, null);
        if (ˊ != null) {
            while (ˊ.moveToNext()) {
                try {
                    try {
                        cfr o_cfr = (cfr) cls.newInstance();
                        o_cfr.ˋ(ˊ);
                        arrayList.add(o_cfr);
                    } catch (Throwable e) {
                        Logger.ˋ("DBHandler", "query exception:", e);
                    } catch (Throwable e2) {
                        Logger.ˋ("DBHandler", "query exception:", e2);
                    }
                } catch (SQLiteException e3) {
                    Logger.e("DBHandler", "query ex: SQLiteException");
                } catch (Throwable e22) {
                    Logger.ˋ("DBHandler", "query list:", e22);
                } finally {
                    ˋ(ˊ);
                }
            }
        }
        ˋ(ˊ);
        return arrayList;
    }

    public <T extends cfr> List<T> ˋ(Class<T> cls, String str, String[] strArr, String str2, String str3) {
        Cursor query;
        Cursor cursor;
        Throwable e;
        List<T> arrayList = new ArrayList();
        try {
            query = this.ˋ.getReadableDatabase().query(this.ˎ, new String[]{"*"}, str, strArr, str2, null, str3);
            if (query != null) {
                while (query.moveToNext()) {
                    try {
                        try {
                            cfr o_cfr = (cfr) cls.newInstance();
                            o_cfr.ˋ(query);
                            arrayList.add(o_cfr);
                        } catch (IllegalAccessException e2) {
                            Logger.e("DBHandler", "query ex:" + e2.toString());
                        } catch (InstantiationException e3) {
                            Logger.e("DBHandler", "query ex: " + e3.toString());
                        }
                    } catch (SQLiteException e4) {
                        cursor = query;
                    } catch (IllegalArgumentException e5) {
                        e = e5;
                    } catch (IllegalStateException e6) {
                        e = e6;
                    }
                }
            }
            ˋ(query);
        } catch (SQLiteException e7) {
            cursor = null;
            try {
                Logger.e("DBHandler", "query ex: SQLiteException");
                ˋ(cursor);
                return arrayList;
            } catch (Throwable th) {
                Throwable th2 = th;
                query = cursor;
                e = th2;
                ˋ(query);
                throw e;
            }
        } catch (IllegalArgumentException e8) {
            e = e8;
            query = null;
            try {
                Logger.ˋ("DBHandler", "query ex:", e);
                ˋ(query);
                return arrayList;
            } catch (Throwable th3) {
                e = th3;
                ˋ(query);
                throw e;
            }
        } catch (IllegalStateException e9) {
            e = e9;
            query = null;
            Logger.ˋ("DBHandler", "query ex:", e);
            ˋ(query);
            return arrayList;
        } catch (Throwable th4) {
            e = th4;
            query = null;
            ˋ(query);
            throw e;
        }
        return arrayList;
    }

    public int ॱ(cfr o_cfr, String str, String[] strArr) {
        int i = 0;
        try {
            i = this.ˋ.getWritableDatabase().update(this.ˎ, o_cfr.J_(), str, strArr);
        } catch (SQLiteException e) {
            Logger.e("DBHandler", "update ex : SQLiteException");
        } catch (Throwable e2) {
            Logger.ˋ("DBHandler", "update ex:", e2);
        }
        return i;
    }

    public int ˋ(String str, String[] strArr) {
        int i = 0;
        try {
            i = this.ˋ.getWritableDatabase().delete(this.ˎ, str, strArr);
        } catch (SQLiteException e) {
            Logger.e("DBHandler", "delete ex: SQLiteException");
        } catch (Throwable e2) {
            Logger.ˋ("DBHandler", "delete ex:", e2);
        }
        return i;
    }

    private void ˋ(Cursor cursor) {
        if (cursor != null) {
            try {
                cursor.close();
            } catch (Throwable e) {
                Logger.ˋ("DBHandler", "closeCursor ex:", e);
            }
        }
    }
}
